package com.it.sqzx.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.sqzx.pojo.Order;
import com.it.sqzx.pojo.User;
import com.it.sqzx.service.OrderService;
import com.it.sqzx.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
* @author lenovo
* @description 针对表【t_order】的数据库操作Service实现
* @createDate 2024-09-13 20:11:43
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService{

    public static final String USER_INVOKE_URL = "http://spzx-cloud-user/user/get/";



    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public User findOrderOwner(Long orderId)
    {
        // 根据id查询订单数据
        Order order = orderMapper.selectById(orderId);
        // 发起远程调用
        User user = restTemplate.getForObject(USER_INVOKE_URL + order.getUserid(), User.class);
        user.setExtrainfo("订单微服务发起调用，本订单属于用户ID: "+user.getId()+" ---用户名称： "+user.getUsername());
        return user;
    }
}




